function isLocal() {
  if (window.location.hostname === "localhost" || window.location.hostname === "127.0.0.1") {
    return true;
  }
  return false;
}

// 设置cookie
function setCookie(name, value, expireDays = (365 * 10)) {
  const exdate = new Date();
  exdate.setDate(exdate.getDate() + expireDays);
  document.cookie = name + "=" + escape(value) +
    ((expireDays == null) ? "" : ";expires=" + exdate.toGMTString());
}

// 取回cookie
function getCookie(name) {
  if (document.cookie.length > 0) {
    let cookieStart = document.cookie.indexOf(name + "=");
    if (cookieStart !== -1) {
      cookieStart = cookieStart + name.length + 1;
      let cookieEnd = document.cookie.indexOf(";", cookieStart);
      if (cookieEnd === -1) cookieEnd = document.cookie.length;
      return unescape(document.cookie.substring(cookieStart, cookieEnd));
    }
  }
  return "";
}

export default {
  setCookie,
  getCookie,
  isLocal,
};
